home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group02b.txt
/
000168_icon-group-sender_Thu Dec 26 18:56:11 2002.msg
< prev
next >
Wrap
Internet Message Format
|
2003-01-02
|
5KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id gBR1rWM08248
for icon-group-addresses; Thu, 26 Dec 2002 18:53:32 -0700 (MST)
Message-Id: <200212270153.gBR1rWM08248@baskerville.CS.Arizona.EDU>
From: "Andrew Hamm" <ahamm@mail.com>
X-Newsgroups: comp.lang.icon
Subject: Re: Scanning question
Date: Fri, 27 Dec 2002 11:29:34 +1100
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
To: icon-group@cs.arizona.edu
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
ernobe wrote:
> I wanted to scan thru several lines in a file searching for strings
> that have been scanned out of another file. So if an operation on a
> specific line fails to produce results, I need to go to the next line
> while keeping count of the number of strings that have been scanned
> (I need to match the string itself and find its position in the file).
> I had something like
>
> var := 1 # number of string
> every line := read() do
> (
> line ? while tab( upto( &letters ) ) do
> str := tab( many( &letters ) ) \ 1,
> count +:= 1,
> if count = var then
> write( file, str ),
> count := 0
> )
OK - I can't see how your sample code does what you mention in the first
paragraph, but you did say "something like" so I guess this is not trying to
do what you want, but trying to understand what is happening?
> The problem is that if a line has no matches, I need to continue with
> another line without setting the count back to zero. 'Every' is not
> a loop structure so I can't put a 'next' in there before the count is
> set back to zero.
Yes, "every" can be "next". Run this sample program:
procedure main()
j := 1
every i := 1 to 10 do
{
write(i, " ", j)
if i % 2 = 1 then next
j +:= 1
}
end
> I realize now that the scanning expression itself
> was not the problem after all. I need to re-organize my program.
> if the 'then' clause fails in the conjunction, does the 'if'
> clause itself fail?
Yes. Depending on the "if" condition, the "then" or the "else" part is
executed. The outcome of the entire statement will be the outcome of the
chosen "then" or "else" part. If the else part is missing, it is like a
failure - effectively a missing else part generates zero results which will
be a failure that will force backtracking.
In either situation, if the "then" or "else" part generates results, that is
the result of the entire "if" statement. Note that the condition is never
resumed - it is driven to produce ANY result so that the "then" or the
"else" part can be selected but after that it is finished.
> If one backtracks into a conjunction,
> does the whole thing resume, or just the final expression?
The whole conjunction. By the way, what you are using is actually called
"mutual evaluation" although it is very similar to "conjunction".
Conjunction is
A & B & C ....
but you are using mutual evaluation:
(A, B, C, ....)
In either case, backtracking can pass through the entire list of A B C as
needed to produce a result. In both cases, the result of the expression is
the result of the last part. Apart from the syntactical difference, mutual
evaluation allows you to select which part you want the value of: for
example
2(A, B, C)
yields the values of B whenever it produces a result. A, B, and C need to
produce a result in each case. For example, run this
procedure main()
every i := 2(1 to 3, 4 to 6, 7 to 9) do
write(i)
end
And you'll see it write 4,4,4,5,5,5,6,6,6 three times ie 3*3*3 results.
Anyway, onto your specific problem. I'm not sure it's worth working on your
sample code since it doesn't sound exactly like your goal. Your use of
mutual evaluation is unusual but by no means wrong. Perhaps it's just me who
doesn't use it very much like this. Actually, since I do use & very often to
chain together expressions into one backtracking extravaganza, I suppose I
do use it a lot ;-) Whatever the reason, if you still need help, please pass
on your actual code so I (or others) can see your goal and where you might
be going wrong.
--
There's nowt wrong wi' owt what mitherin' clutterbucks don't barly grummit!
-
Replies directly to this message will go to an account that may not be
checked for a week or two. For more timely e-mail response, use (only
in an emergency) ahamm sanderson net au with all the usual punctuation.